import Vue from 'vue'
import server from '@/api/index'
import { removeSpaces } from '~/plugins/tools'
const TZY_SERVER_ENV = process.env.TZY_SERVER_ENV
const BASE = require('~/config/index.js')
export default function ({ app }) {
    const API = {}
    Object.values(server).forEach((item) => {
        item.forEach((subItem) => {
            API[`${subItem.module ? subItem.module + '/' : ''}${subItem.name}`] = (params) => {
                return app.$axios({
                    pathParams: subItem.pathParams || false,
                    url: subItem.url,
                    method: subItem.method,
                    data: removeSpaces(params),
                    headers: {
                        'Content-Type': subItem.contentType === 'formData' ? 'multipart/form-data' : 'application/json'
                    }
                })
            }
        })
    })
    Vue.prototype.$ApiServer = API
    Vue.prototype.$staticUrl = BASE[TZY_SERVER_ENV].staticUrl
    app.$ApiServer = API
    app.$staticUrl = BASE[TZY_SERVER_ENV].staticUrl
}
